import tkinter as tk
from tkinter import ttk
import os

if __name__ == '__main__':
    # 创建根窗口
    root = tk.Tk()
    root.title("报岗信息生成")
    # root.resizable(False,False)
    root.geometry("600x400")

    data_set = [('是', 1),
                ('否', 0)]
    font_size = 12
    label_length = 70

    label_person = tk.Label(root, text='人员是否有变化', font=('微软雅黑', font_size,), wraplength=label_length)
    label_car = tk.Label(root, text='车牌号是否有变化', font=('微软雅黑', font_size,), wraplength=label_length)
    label_driver_status = tk.Label(root, text='司机是否有变化', font=('微软雅黑', font_size,), wraplength=label_length)
    label_pc = tk.Label(root, text='电脑是否有变化', font=('微软雅黑', font_size,), wraplength=label_length)
    label_car_id = tk.Label(root, text='车牌号', font=('微软雅黑', font_size,))
    label_driver = tk.Label(root, text='司机', font=('微软雅黑', font_size,))

    root.update()
    win_width = root.winfo_width()
    win_height = root.winfo_height()
    first_interval_width = int(win_width * 0.09)
    first_interval_height = int(win_height * 0.05)
    interval_between = 8
    label_person.grid(row=0, column=0, padx=first_interval_width,
                      pady=first_interval_height)
    label_car.grid(row=0, column=1, padx=interval_between)
    label_driver_status.grid(row=0, column=2, padx=first_interval_width)
    label_pc.grid(row=0, column=3, padx=interval_between)
    # 第一次定义好列之间距离，后面就不用定义了，调整行间距即可
    font_scale = 0.9
    person_cbox = ttk.Combobox(root, width=2, font=('微软雅黑', int(font_size * font_scale)))
    person_cbox['value'] = ('是', '否')
    person_cbox.grid(row=1, column=0)
    person_cbox.current(1)

    var_str = tk.StringVar()
    car_cbox = ttk.Combobox(root, textvariable=var_str, width=2, font=('微软雅黑', int(font_size * font_scale)))
    car_cbox['value'] = ('是', '否')
    car_cbox.grid(row=1, column=1)
    car_cbox.current(1)

    driver_cbox = ttk.Combobox(root, width=2, font=('微软雅黑', int(font_size * font_scale)))
    driver_cbox['value'] = ('是', '否')
    driver_cbox.grid(row=1, column=2)
    driver_cbox.current(1)

    pc_cbox = ttk.Combobox(root, width=2, font=('微软雅黑', int(font_size * font_scale)))
    pc_cbox['value'] = ('是', '否')
    pc_cbox.grid(row=1, column=3)
    pc_cbox.current(1)


    def get_car_status(event):
        print(var_str.get())


    def test():
        person_flag = False
        car_flag = False
        driver_flag = False
        pc_flag = False
        if person_cbox.get() == '是':
            person_flag = True
            print('人员信息有变化')
        else:
            print('人员信息无变化')

        if pc_cbox.get() == '是':
            pc_flag = True
            print('电脑信息有变化')
        else:
            print('电脑信息无变化')
        if person_flag:
            os.system('J:/py_interpreter/Scripts/python.exe F:/code_test/python/daily_report/change_content.py new')
        else:
            os.system('J:/py_interpreter/Scripts/python.exe F:/code_test/python/daily_report/change_content.py')

        if pc_flag or person_flag:
            # todo 3月14号的报岗替换，程序有误
            label_car_id.grid(row=2, column=0, pady=first_interval_height)
            os.system('J:/py_interpreter/Scripts/python.exe F:/code_test/python/daily_report/update_word.py new')
        else:
            label_car_id.grid_forget()
            os.system('J:/py_interpreter/Scripts/python.exe F:/code_test/python/daily_report/update_word.py')


    # pc_cbox.bind('<<ComboboxSelected>>', get_car_status)
    print()
    cmd_generate = tk.Button(root, text='生成文件', command=test, font=('微软雅黑', int(font_size * 1.1)))
    cmd_quit = tk.Button(root, text='退出', command=lambda: root.destroy(), font=('微软雅黑', int(font_size * 1.1)))

    cmd_generate.grid(row=4, column=0, padx=first_interval_width, pady=first_interval_width)
    cmd_quit.grid(row=4, column=3, pady=first_interval_width)
    root.mainloop()
